use crate::audio::AudioStore; // 音频管理器
use crate::events::Event; // 事件管理器
use ggez::event::KeyCode; // 键盘输入事件
use specs::World;  // 实体组件系统 World

use std::{fmt::{self, Display}, time::Duration};  // 时间管理器

// Resources
#[derive(Default)]
pub struct InputQueue {
    pub keys_pressed: Vec<KeyCode>,  // 按下的键盘输入
}

pub fn register_resources(world: &mut World) {
    world.insert(InputQueue::default()); // 注册 InputQueue 资源
    world.insert(Gameplay::default()); // 注册 Gameplay 资源   的默认值 默认空
    world.insert(Time::default());
    world.insert(EventQueue::default());
    world.insert(AudioStore::default());
}

pub enum GameplayState {
    Playing,
    Won,
}

impl Display for GameplayState {
    fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str(match self {
            GameplayState::Playing => "Playing",
            GameplayState::Won => "Won",
        })?;
        Ok(())
    }
}

impl Default for GameplayState {
    fn default() -> Self {
        Self::Playing
    }
}

#[derive(Default)]
pub struct Gameplay {
    pub state: GameplayState,
    pub moves_count: u32,
}

#[derive(Default)]
pub struct Time {
    pub delta: Duration,
}

#[derive(Default)]
pub struct EventQueue {
    pub events: Vec<Event>,
}
